/* 
 * File:   SwapFileManager.h
 * Author: bharat
 *
 * Created on October 26, 2009, 12:59 PM
 */

#ifndef _SWAPFILEMANAGER_H
#define	_SWAPFILEMANAGER_H

#include "../threads/synch.h"
#include "machine.h"
#include "bitmap.h"
#include "../filesys/openfile.h"

#define SWAP_FILE_NAME "SwapFile"

class SwapFileManager {
private:
    OpenFile *swapFile; // handle for the swap file
    BitMap *swapBM; // bitmap to keep track of empty swap locations
    Lock *swapLock; // for execlusive access in swap operations

public:
    SwapFileManager(); //default constructor

    /* Reads the page wiht offset into the menory
     * Returns 1 on  success, -1 on fail
     * ppn = destination PPN in memory
     * offset = swap-page offset into swap file
     */
    int readPageFromSwapFile(int ppn, int offset);


    /* Write a page into the swapfile.
     * Returns the swap-file offset on success, else -1
     * ppn = PPN of a page in memory to evict
     */
    int writePageToSwapFile(int ppn);


    /* Marks the entry as empty in swap bitmap.
     * This method is called whenver a process ends
     */
    void markPageAsVoid(int ppn);

};

#endif	/* _SWAPFILEMANAGER_H */

